<script setup lang="ts">
import JSON5 from 'json5';
import type { UseValidationRule } from '@/composable/validation';
import { withDefaultOnError } from '@/utils/defaults';

const defaultValue = '{\n\t"hello": [\n\t\t"world"\n\t]\n}';
const transformer = (value: string) => withDefaultOnError(() => JSON.stringify(JSON5.parse(value), null, 0), '');
const { t } = useI18n();

const rules: UseValidationRule<string>[] = [
  {
    validator: (v: string) => v === '' || JSON5.parse(v),
    message: t('tools_json_minify_json_minify_a283e6ca'),
  },
];
</script>

<template>
  <format-transformer
    input-:label="t('tools_json_minify_json_minify_e9f0e4dd')"
    :input-default="defaultValue"
    input-:placeholder="t('tools_json_minify_json_minify_6e59f8ae')"
    output-:label="t('tools_json_minify_json_minify_c29f05d4')"
    output-language="json"
    :input-validation-rules="rules"
    :transformer="transformer"
  />
</template>
